﻿using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YanZhiwei.DotNet3._5.Utilities.Common
{
    /// <summary>
    /// String帮助类
    /// </summary>
    public static class StringHelper
    {
        #region 从字符串中排出特殊字符
        /// <summary>
        /// 从字符串中排出特殊字符
        /// eg:var str = s.ExceptChars(new HashSet<char>(new[] { ' ', '\t', '\n', '\r' }));
        /// </summary>
        /// <param name="str">需要处理的字符串</param>
        /// <param name="toExclude">排除的字符</param>
        /// <returns>处理后的字符串</returns>
        public static string ExceptChars(this string str, IEnumerable<char> toExclude)
        {
            int _length = str.Length;
            if (_length > 0)
            {
                StringBuilder _builder = new StringBuilder(_length);
                for (int i = 0; i < str.Length; i++)
                {
                    char _c = str[i];
                    if (!toExclude.Contains(_c))
                        _builder.Append(_c);
                }
                return _builder.ToString();
            }
            return str;
        }
        #endregion 
    }
}
